package net.anzhuo.service.impl;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsPledgeMapper;
import net.anzhuo.entity.GsPledge;
import net.anzhuo.service.GsPledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class GsPledgeServiceImpl implements GsPledgeService {

	@Autowired
	private GsPledgeMapper gsPledgeMapper;
	
	@Override
	public GsPledge getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsPledgeMapper.getById(id);
	}

	@Override
	public List<GsPledge> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsPledgeMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsPledge> getListWithPage(GsPledge gsPledge) {
		PaginationVO<GsPledge> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsPledgeMapper.getListWithPage(gsPledge));
		paginationVO.setTotalCount(gsPledgeMapper.getCount(gsPledge.getCoMd5()));
		paginationVO.setTotalPage((gsPledgeMapper.getCount(gsPledge.getCoMd5()) + gsPledge.getPageSize() -1)  / gsPledge.getPageSize()+1);
		paginationVO.setPageNo(gsPledge.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsPledge> getList() {
		// TODO Auto-generated method stub
		return  gsPledgeMapper.getList();
	}

	@Override
	public List<GsPledge> getList(GsPledge gsPledge) {
		// TODO Auto-generated method stub
		return gsPledgeMapper.getListByQuery(gsPledge);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsPledge gsPledge) {
		// TODO Auto-generated method stub
		gsPledgeMapper.update(gsPledge);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsPledge gsPledge) {
		// TODO Auto-generated method stub
		gsPledgeMapper.save(gsPledge);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsPledge gsPledge = gsPledgeMapper.getById(id);
		if (gsPledge == null) {
//			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsPledgeMapper.update(gsPledge);

	}

}
